package com.sikaryofficial.job.task;

import com.sikaryofficial.common.core.constant.ReportConstant;
import com.sikaryofficial.common.core.exception.ServiceException;
import com.sikaryofficial.common.core.utils.StringUtils;
import com.sikaryofficial.system.api.RemotePointBalanceService;
import com.sikaryofficial.system.api.RemoteProductService;
import com.sikaryofficial.system.api.RemoteReportService;
import com.sikaryofficial.system.api.RemoteSystemReportService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 定时任务调度测试
 *
 * @author ruoyi
 */
@Component("ryTask")
public class RyTask {
    private static final Logger log = LoggerFactory.getLogger(RyTask.class);
    @Autowired
    private RemoteReportService remoteReportService;
    @Autowired
    private RemoteProductService remoteProductService;
    @Autowired
    private RemotePointBalanceService remotePointBalanceService;
    @Autowired
    private RemoteSystemReportService remoteSystemReportService;

    public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) {
        System.out.println(StringUtils.format("执行多参方法： 字符串类型{}，布尔类型{}，长整型{}，浮点型{}，整形{}", s, b, l, d, i));
    }

    public void ryParams(String params) {
        System.out.println("执行有参方法：" + params);
    }

    public void ryNoParams() {
        System.out.println("执行无参方法");
    }

    /**
     * 自动完成举报
     */
    public void ryAutoCompleteReport() {
        remoteReportService.autoProcess();
    }

    /**
     * 自动处理处理获奖邮件发送
     */
    public void autoSendAwardsEmailNotice() {
        remoteProductService.autoSendAwardsEmailNotice();
    }

    /**
     * 积分清除邮件通知
     */
    public void autoSendResetEmailNotice() {
        remotePointBalanceService.autoSendResetEmailNotice();
    }

    /**
     * 积分清除
     */
    public void autoResetUnusedPoints() {
        remotePointBalanceService.autoResetUnusedPoints();
    }

    /**
     * 用户日活
     * 时间类型:day-天,week-周,month-月,quarter-季度,year-年
     */
    public void userActivityDaily(String timeType) {
        log.info("用户日活-timeType:" + timeType);
        if (StringUtils.isBlank(timeType)) {
            throw new ServiceException("Time type is error.");
        }
        boolean checkTypeFlag = ReportConstant.DAY_TYPE.equals(timeType)
                || ReportConstant.WEEK_TYPE.equals(timeType)
                || ReportConstant.MONTH_TYPE.equals(timeType)
                || ReportConstant.QUARTER_TYPE.equals(timeType)
                || ReportConstant.YEAR_TYPE.equals(timeType);
        if (Boolean.FALSE.equals(checkTypeFlag)) {
            throw new ServiceException("Time type is error.");
        }
        remoteSystemReportService.activityByType(timeType);
    }

    /**
     * 用户注册job
     * 时间类型:day-天,week-周,month-月,quarter-季度,year-年
     */
    public void userRegisterDaily(String timeType) {
        log.info("用户注册-timeType:" + timeType);
        if (StringUtils.isBlank(timeType)) {
            throw new ServiceException("Time type is error.");
        }
        boolean checkTypeFlag = ReportConstant.DAY_TYPE.equals(timeType)
                || ReportConstant.WEEK_TYPE.equals(timeType)
                || ReportConstant.MONTH_TYPE.equals(timeType)
                || ReportConstant.QUARTER_TYPE.equals(timeType)
                || ReportConstant.YEAR_TYPE.equals(timeType);
        if (Boolean.FALSE.equals(checkTypeFlag)) {
            throw new ServiceException("Time type is error.");
        }
        remoteSystemReportService.registerByType(timeType);
    }
}
